package com.sk.weichat.ui.groupchat;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sk.weichat.AppConstant;
import com.sk.weichat.R;
import com.sk.weichat.bean.message.MucRoomMember;
import com.sk.weichat.db.InternationalizationHelper;
import com.sk.weichat.helper.AvatarHelper;
import com.sk.weichat.ui.base.BaseActivity;
import com.sk.weichat.ui.me.PersonalCenterActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: chenzl
 * @ClassName: GroupManageActivity
 * @Description: 公开群管理员列表
 * @CreateDate: 2019/9/16 11:50
 */
public class GroupManageActivity extends BaseActivity {


    private RecyclerView recyManage;
    private List<MucRoomMember> members = new ArrayList<>();
    private GroupManageAdapter mAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_group_manage);
        getSupportActionBar().hide();
        initView();
    }

    private void initView(){
        members = ( List<MucRoomMember>)getIntent().getSerializableExtra("members");

        findViewById(R.id.iv_title_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        TextView tvTitle =  findViewById(R.id.tv_title_center);
        tvTitle.setText(R.string.group_manager);
        recyManage = findViewById(R.id.recy_manage);
        recyManage.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new GroupManageAdapter(members);
        recyManage.setAdapter(mAdapter);
    }

    class GroupManageAdapter extends BaseQuickAdapter<MucRoomMember,BaseViewHolder>{

        public GroupManageAdapter(List<MucRoomMember> data) {
            super(R.layout.row_sort_friend, data);
        }
        @Override
        protected void convert(BaseViewHolder helper, MucRoomMember item) {

            TextView categoryTitleTv = helper.getView(R.id.catagory_title);
            categoryTitleTv.setVisibility(View.GONE);
            ImageView avatar_img = helper.getView(R.id.avatar_img);
            TextView nick_name_tv = helper.getView(R.id.nick_name_tv);
            AvatarHelper.getInstance().displayAvatar(item.getUserId(), avatar_img, true);
            nick_name_tv.setText(TextUtils.isEmpty(item.getRemarkName())?item.getNickName():item.getRemarkName());
            TextView roles = helper.getView(R.id.roles);
            roles.setVisibility(View.VISIBLE);
            if (item.getRole() == 1) {
                roles.setBackgroundResource(R.drawable.bg_role1);
                roles.setText(InternationalizationHelper.getString("JXGroup_Owner"));
            } else if (item.getRole() == 2) {
                roles.setBackgroundResource(R.drawable.bg_role5);
                roles.setText(InternationalizationHelper.getString("JXGroup_Admin"));
            }
        }
    }
}
